package Basic.day05;

import java.util.Arrays;

public class MaxToLast {
    public static void main(String[] args) {
        int[] arr = new int[10];
        //随机生成0~99的数字并填入数组中
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random()*100);
            System.out.println("arr[" + i + "]= " + arr[i]);
        }

        System.out.println("--------------------");
        //找出数组中的最大值
        MaxOfArrayUtil maxOfArrayUtil = new MaxOfArrayUtil();
        int maxIndex = maxOfArrayUtil.getIndex(arr);
        System.out.println("最大值是：" + arr[maxIndex] + "，下标是：" + maxIndex);
        //将最大值放到数组的最后
        int[] newArray = Arrays.copyOf(arr, arr.length + 1);
        newArray[newArray.length - 1] = arr[maxIndex];
        //输出检查
        for (int i = 0; i < newArray.length; i++) {
            System.out.println("newArray[" + i + "]= " + newArray[i]);
        }
    }
}
